package com.xyf.controller;

import com.seventh.common.pojo.R;
import com.xyf.pojo.entity.TbMaintainShop;
import com.xyf.pojo.vo.MaintainShopVo;
import com.xyf.service.TbMaintainShopService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: clms-seventh
 * @description: MaintainShop控制层
 * @author: 徐亚飞
 * @create: 2021-07-23 10:13
 **/
@RestController
@RequestMapping("safeguard/maintainShop")
@Api(tags="维修厂控制层")
public class TbMaintainShopController {

    @Autowired
    TbMaintainShopService tbMaintainShopService;

    @PostMapping("/initMaintainShopTable/{currentPage}/{pageSize}")
    @ApiOperation("分页查询维修厂")
    public R findAllMaintainShopByPage(
            @ApiParam(name = "currentPage", value = "页码", required = true)
            @PathVariable("currentPage")Integer currentPage,
            @ApiParam(name = "pageSize", value = "每页多少条", required = true)
            @PathVariable("pageSize") Integer pageSize,
            @ApiParam(name = "maintainShopVo", value = "查询条件", required = false)
            @RequestBody MaintainShopVo maintainShopVo
    ){

        return tbMaintainShopService.findAllMaintainShopByPage(currentPage,pageSize,maintainShopVo);
    }

    @GetMapping("selectById/{id}")
    @ApiOperation("根据Id查询维修厂")
    public TbMaintainShop selectById(
            @ApiParam(name = "id", value = "维修厂ID", required = true)
            @PathVariable Integer id){
        TbMaintainShop tbMaintainShop = tbMaintainShopService.selectById(id);
        return tbMaintainShop;
    }

    @PostMapping("insertMaintainShop")
    @ApiOperation("添加维修场")
    public R insertMaintainShop(
            @ApiParam(name = "tbMaintainShop", value = "维修厂实体类", required = true)
            @RequestBody TbMaintainShop tbMaintainShop){
        System.out.println(tbMaintainShop);
        return tbMaintainShopService.insertMaintainShop(tbMaintainShop);
    }
    @DeleteMapping("deleteById/{id}")
    @ApiOperation("根据Id删除维修厂")
    public R deleteMaintainShop(
            @ApiParam(name = "id", value = "维修厂ID", required = true)
            @PathVariable Integer id){
        return tbMaintainShopService.deleteMaintainShop(id);

    }

    @PutMapping("update")
    @ApiOperation("根据Id修改维修厂")
    public R updateMaintainShop(
            @ApiParam(name = "tbMaintainShop", value = "维修厂实体类", required = true)
            @RequestBody TbMaintainShop tbMaintainShop){
      return tbMaintainShopService.updateMaintainShop(tbMaintainShop);
    }

    @PostMapping("/findAllShops")
    @ApiOperation("查询所有维修厂名")
    public List<TbMaintainShop> findAllShops(){
        return tbMaintainShopService.findAllShops();
    }

    @PostMapping("/selectByName")
    @ApiOperation("维修厂名唯一校验")
    public R selectByName(
            @ApiParam(name = "tbMaintainShop", value = "维修厂实体类", required = true)
            @RequestBody TbMaintainShop tbMaintainShop){
        return tbMaintainShopService.selectByName(tbMaintainShop.getId(), tbMaintainShop.getName());
    }


}
